package view.components
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.text.TextFormat;
	
	import utils.DisplayTool;
	
	public class NumericStepper extends Sprite
	{
		private var org:*;
		
		public function NumericStepper()
		{
			initOrg();
			drawBg();
		}
		
		private function drawBg():void
		{
			with(this.graphics)
			{
				clear();
				beginFill(0xBBBBBB);
				drawRoundRect(0,0,org.width,org.height - 1,10,10);
				endFill();
			}
		}
		
		public function destroy():void
		{
			org.textField.textField.removeEventListener(Event.CHANGE,onChange);
			org = null;
			
			DisplayTool.removeAllChild(this);
		}
		
		private function initOrg():void
		{
			org = UIComponents.getNumericStepper();
			org.textField.textField.addEventListener(Event.CHANGE,onChange);
			addChild(org);
		}
		
		private function onChange(event:Event):void
		{
			if (int(org.textField.textField.text) > org.maximum)
			{
				org.textField.textField.text = String(org.maximum);
				//org.value = org.maximum;
			}
		}
		
		override public function set mouseEnabled(enabled:Boolean) : void
		{
			super.mouseEnabled = enabled;
			org.enabled = enabled;
		}
		
		
		public function get value():Number
		{
			return int(org.textField.textField.text);
		}
		
		public function set value(v:Number):void
		{
			org.value = v;
		}
		
		public function set maximum(v:Number):void
		{
			org.maximum  = v;
		}
		
		public function set minimun(v:Number):void
		{
			org.minimum = v;
		}
		
		public function set stepSize(v:Number):void
		{
			org.stepSize = v;
		}
		
		override public function set width(value:Number) : void
		{
			org.width = value;
			drawBg();
		}
		
		override public function set height(value:Number) : void
		{
			org.height = value;
			drawBg();
		}
		
		override public function get width() : Number
		{
			return org.width;
		}
		
		override public function get height() : Number
		{
			return org.height;
		}
	}
}